﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Library.Domain;

namespace Core.Messages
{
    /// <summary>
    /// Response is used to implement the Request-Response pattern.
    /// All returned objects in the Service layer should inherit from this class.
    /// </summary>
    [DataContract()]    
    public class Response
    {        
        [DataMember()]
        public bool ShowNotification { get; set; }        
        
        [DataMember()]
        public bool Success { get; set; }
                
        [DataMember()]
        public string ErrorMessage { get; set; }        
       
        [DataMember()]
        public List<ValidationRule> BrokenRules { get; set; }

        public Response()
            : this(false, new List<ValidationRule>())
        {        
        }
        
        public Response(bool success, List<ValidationRule> brokenRules) : this(success, brokenRules, null)
        {         
        }

        public Response(bool success, List<ValidationRule> brokenRules, string errorMessage)
        {
            Success = success;
            BrokenRules = brokenRules;
            ErrorMessage = errorMessage;
            ShowNotification = true;
        }
    }

    [DataContract()]
    public class Response<T> : Response
    {
        public Response(T value)
        {
            this.Value = value;
        }

        public Response()
        {
        }

        [DataMember()]
        public T Value { get; set; }
    }
}
